
export default {
    components: {
        projHandleDisplay: require("@/pages/biz/proj/projDisplay/projHandleDisplay.vue")
          .default
      },
    name: "Index",
    data() {
        return {
            ids: [],
            designerVisible:false,
            searchForm: {
              name: ''
            },
            tableData: [],
            pager: {
                page: 0,
                size: 20,
                total: 0
            },
            dialogTitle: '流程实例',
            entityId: '',
            instanceState: [{key:"1",label:"运行中" ,style:"color:green;"},{key:"2",label:"暂停",style:"color:yellow;"},{key:"3",label:"正常终止",style:"color:red;"},{key:"4",label:"异常终止",style:"color:purple;"}],
        }
    },
    computed: {
        height() {
            return `calc(100vh - 350px)`;
        }
    },
    mounted() {
        this.getList();
    },
    methods: {
        //恢复
        doResume: function (item){

            this.entityId = item.id;
            let params = {
                id : this.entityId
            };
            this.$api.post(   '/wf/workflowInstance/resume', params).then(res => {
                if (res.status === '0') {
                    this.$message({
                        type: 'success',
                        message: res.message
                    });
                    this.getList();
                }else{
                    this.$message({
                        type: 'error',
                        message: res.message
                    });
                }
            });
        },

        // 暂缓
        doPause: function (item) {

            this.entityId = item.id;
            let params = {
                id : this.entityId
            };
            this.$api.post(   '/wf/workflowInstance/pause', params).then(res => {
                if (res.status === '0') {
                    this.$message({
                        type: 'success',
                        message: res.message
                    });
                    this.getList();
                }else{
                    this.$message({
                        type: 'error',
                        message: res.message
                    });
                }
            });
        },

        // 终止
        doEnd: function(item){

            this.entityId = item.id;
            let params = {
                id : this.entityId
            };
            this.$api.post(  '/wf/workflowInstance/end', params).then(res => {
                if (res.status === '0') {
                    this.$message({
                        type: 'success',
                        message: res.message
                    });
                    this.getList();
                }else{
                    this.$message({
                        type: 'error',
                        message: res.message
                    });
                }
            });
        },

        // 获取任务列表
        getList: function () {
            let params = {
                page: this.pager.page === 0 ? this.pager.page : this.pager.page - 1,
                size: this.pager.size,
                name: this.searchForm.name || '',
                projectCode:this.searchForm.projectCode || '',
                projectName:this.searchForm.projectName || ''
            };
            this.$api.formPost(  '/api/biz/flowInstance/doGetList', params).then(res => {
                if (res.retHead.code === '0000000') {
                    if(null!=res.retBody){
                        this.tableData = res.retBody;
                        this.pager.total = res.retBody[0].total;
                    }else{
                        this.tableData = res.retBody;
                        this.pager.total = 0;
                    }
                    
                     
                }
            });
        },
        handleSelectionChange: function (val) {
            this.ids = val;
            //console.log(this.ids);
        },

        dateFormatter: function (row, column) {
            let datetime = row[column.property];
            if(datetime){
                datetime = new Date(datetime);
                let y = datetime.getFullYear() + '-';
                let mon = datetime.getMonth()+1 + '-';
                let d = datetime.getDate();
                return y + mon + d;
            }
            return ''
        },
      handleSizeChange(val) {
        this.pager.size = val;
        this.getList();
      },
      handleCurrentChange(val) {
        this.pager.page = val;
        this.getList();
      },
      progress(item){
    
        let path = '/flow/taskWorkitem';
        this.$router.push({
            path: path,
            query: { id: item.id }
        });
      },
      showDetail(item){
        this.designerVisible=true;
        this.$nextTick(()=>{
            this.$refs.projHandleDisplay.innit(item.mid);
        })
        
      }
    }
}
